package com.lry.jvm.rtda;

import com.lry.jvm.rtda.heap.JMethod;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Frame {

    public Frame next;

    private LocalVars localVars;

    private OperandStack operandStack;

    private JThread thread;

    private int nextPc;

    private JMethod method;

    public Frame(int maxLocals, int maxStack){
        localVars = new LocalVars(maxLocals);
        operandStack = new OperandStack(maxStack);
    }

    public Frame(JThread thread, int maxLocals, int maxStack) {
        this.thread = thread;
        localVars = new LocalVars(maxLocals);
        operandStack = new OperandStack(maxStack);
    }

    public Frame(JThread thread, JMethod method){
        this.thread = thread;
        this.method = method;
        localVars = new LocalVars(method.getMaxLocals());
        operandStack = new OperandStack(method.getMaxStack());
    }

    public void revertNextPc() {
        nextPc = thread.getPc();
    }
}
